package com.blue.integration.pay.swift;

import com.blue.core.dict.Type;
import com.blue.core.util.MoneyUtil;
import com.blue.core.util.NetworkUtil;
import com.blue.core.util.RandomUtil;

/**
 * 威富通XML请求参数
 *
 * @author zhengjin
 * @since 1.0 2017年12月13日
 */
public class XmlSwiftPayRequest
{
	private String mchId; //商户号
	private String key; //商户秘钥
	private String service; //接口类型
	private String version; //版本号
	private String charset = "UTF-8"; //字符编码
	private String singType = "MD5"; //加密方式
	private String outTradeNo; //商户订单号 商户系统内部的订单号 ,32个字符内、 可包含字母,确保 在商户系统唯一
	private String body; //商品描述
	private String isRaw; // 是否原生支付，1为是，0或空为否
	private String subOpenid; //微信用户关注商家公众号的 openid
	private String totalFee; //总金额
	private String mchCreateIp; //终端IP
	private String notifyUrl; //通知地址
	private String callbackUrl; //前台跳转地址
	private String nonceStr; //随机字符串
	private String limitCreditPay; //是否限制信用卡  值为 1，禁用信用卡；值为 0 或者不传此参数则不禁用
	private Integer swiftPayType; //
	private Integer isRequestPay;
	private String timeStart; //订单生成时间
	private String timeExpire; //订单失效时间

	public XmlSwiftPayRequest()
	{
	}

	public static XmlSwiftPayRequest toRequest(SwiftPayRequest request, SwiftConfig config)
	{
		if (request == null)
			return null;

		XmlSwiftPayRequest xml = new XmlSwiftPayRequest();
		xml.setMchId(config.getMchId());
		xml.setKey(config.getKey());
		xml.setService(request.getService().getName());
		xml.setVersion(request.getService().getVersion());
		xml.setSubOpenid(request.getOpenid());
		xml.setOutTradeNo(request.getOrderNo());
		xml.setBody(request.getBody());
		xml.setIsRaw(request.getIsRaw() == null || request.getIsRaw() == Type.NO ? null : "1");
		xml.setTotalFee(String.valueOf(MoneyUtil.wxpayFee(request.getMoney())));
		xml.setNotifyUrl(request.getNotifyUrl());
		xml.setCallbackUrl(request.getReturnUrl());
		xml.setLimitCreditPay(request.getLimitCreditPay() == null || request.getLimitCreditPay() == Type.NO ? null : "1");
		xml.setMchCreateIp(NetworkUtil.getAddress());
		xml.setNonceStr(RandomUtil.rand(RandomUtil.RandomType.UPPER_CASE_NUMBER, 32));
		return xml;
	}

	public String getMchId()
	{
		return mchId;
	}

	public void setMchId(String mchId)
	{
		this.mchId = mchId;
	}

	public String getKey()
	{
		return key;
	}

	public void setKey(String key)
	{
		this.key = key;
	}

	public String getService()
	{
		return service;
	}

	public void setService(String service)
	{
		this.service = service;
	}

	public String getVersion()
	{
		return version;
	}

	public void setVersion(String version)
	{
		this.version = version;
	}

	public String getCharset()
	{
		return charset;
	}

	public void setCharset(String charset)
	{
		this.charset = charset;
	}

	public String getSingType()
	{
		return singType;
	}

	public void setSingType(String singType)
	{
		this.singType = singType;
	}

	public String getOutTradeNo()
	{
		return outTradeNo;
	}

	public void setOutTradeNo(String outTradeNo)
	{
		this.outTradeNo = outTradeNo;
	}

	public String getBody()
	{
		return body;
	}

	public void setBody(String body)
	{
		this.body = body;
	}

	public String getIsRaw()
	{
		return isRaw;
	}

	public void setIsRaw(String isRaw)
	{
		this.isRaw = isRaw;
	}

	public String getSubOpenid()
	{
		return subOpenid;
	}

	public void setSubOpenid(String subOpenid)
	{
		this.subOpenid = subOpenid;
	}

	public String getTotalFee()
	{
		return totalFee;
	}

	public void setTotalFee(String totalFee)
	{
		this.totalFee = totalFee;
	}

	public String getMchCreateIp()
	{
		return mchCreateIp;
	}

	public void setMchCreateIp(String mchCreateIp)
	{
		this.mchCreateIp = mchCreateIp;
	}

	public String getNotifyUrl()
	{
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl)
	{
		this.notifyUrl = notifyUrl;
	}

	public String getCallbackUrl()
	{
		return callbackUrl;
	}

	public void setCallbackUrl(String callbackUrl)
	{
		this.callbackUrl = callbackUrl;
	}

	public String getNonceStr()
	{
		return nonceStr;
	}

	public void setNonceStr(String nonceStr)
	{
		this.nonceStr = nonceStr;
	}

	public String getLimitCreditPay()
	{
		return limitCreditPay;
	}

	public void setLimitCreditPay(String limitCreditPay)
	{
		this.limitCreditPay = limitCreditPay;
	}

	public Integer getSwiftPayType()
	{
		return swiftPayType;
	}

	public void setSwiftPayType(Integer swiftPayType)
	{
		this.swiftPayType = swiftPayType;
	}

	public Integer getIsRequestPay()
	{
		return isRequestPay;
	}

	public void setIsRequestPay(Integer isRequestPay)
	{
		this.isRequestPay = isRequestPay;
	}

	public String getTimeStart()
	{
		return timeStart;
	}

	public void setTimeStart(String timeStart)
	{
		this.timeStart = timeStart;
	}

	public String getTimeExpire()
	{
		return timeExpire;
	}

	public void setTimeExpire(String timeExpire)
	{
		this.timeExpire = timeExpire;
	}
}
